package com.xuyiwei.mayi.test;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 * Created by xuyiwei on 2019/5/6.
 */
public class JdkProxyDemo1 implements InvocationHandler {
    private Object target;

    public JdkProxyDemo1(Object target) {
        this.target = target;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        System.out.println("jdk动态代理开启");
        Object o = method.invoke(target,args);
        System.out.println("jdk动态代理关闭");
        return o;
    }

    public static void main(String[] args) {
        HoseImpl imp = new HoseImpl();
        JdkProxyDemo1 jdkProxyDemo1 = new JdkProxyDemo1(imp);
        Hose hose  = (Hose) Proxy.newProxyInstance(HoseImpl.class.getClassLoader(),HoseImpl.class.getInterfaces(),jdkProxyDemo1);
        hose.mai();
    }
}
